package com.iotek.bookstore.modle.dao.impl;

import com.iotek.bookstore.modle.entity.BookDetails;
import com.iotek.bookstore.util.PreparedStatementSetter;
import com.iotek.bookstore.util.RsCallBackHandler;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class BookDetailsDaoImpl extends MyBookstoreDaoImpl<BookDetails>{
    @Override
    public List<BookDetails> query(final int id) {
        String sql="SELECT bookId,cover,book,writer,press,publicationTime,intro,pricing,price," +
            "printingTime,print,ISBN,words,pages,format,sheet,pack,contentIntro,writerIntro,catalog,mediaComments,excerpt,repertory FROM book\n" +
            "INNER JOIN bookdetails\n" +
            "on bookId=bookDetailsId where bookId=?";
        this.query(sql, new PreparedStatementSetter() {
            public void setValues(PreparedStatement pstmt) throws SQLException {
                pstmt.setInt(1, id);
            }
        }, new RsCallBackHandler() {
            public void processRs(ResultSet rs) throws SQLException {
                while (rs.next()){
                    BookDetails book=new BookDetails();
                    book.setBookId(rs.getInt(1));
                    book.setCover(rs.getString(2));
                    book.setBook(rs.getString(3));
                    book.setWriter(rs.getString(4));
                    book.setPress(rs.getString(5));
                    book.setPublicationTime(rs.getString(6));
                    book.setIntro(rs.getString(7));
                    book.setPricing(rs.getDouble(8));
                    book.setPrice(rs.getDouble(9));
                    book.setPrintingTime(rs.getString(10));
                    book.setPrint(rs.getInt(11));
                    book.setISBN(rs.getString(12));
                    book.setWords(rs.getInt(13));
                    book.setPages(rs.getInt(14));
                    book.setFormat(rs.getString(15));
                    book.setSheet(rs.getString(16));
                    book.setPack(rs.getString(17));
                    book.setContentIntro(rs.getString(18));
                    book.setWriterIntro(rs.getString(19));
                    book.setCatalog(rs.getString(20));
                    book.setMediaComments(rs.getString(21));
                    book.setExcerpt(rs.getString(22));
                    book.setRepertory(rs.getInt(23));
                    list.add(book);
                }
            }
        });
        return list;
    }

}
